package com.test.entity;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;


@Aspect//声明为切面
@Component//注册为Bean
public class StudentAOP {

    @Before("execution(* com.test.entity.Student.study(..))")
    public void before(JoinPoint point){
        System.out.println("before");
        System.out.println("args:"+Arrays.toString(point.getArgs()));
    }
    @After(value = "execution(* com.test.entity.Student.study(..)) && args(str)",argNames = "str")
    public void after(String str){//获取指定参数
        System.out.println("get arg str:" + str);
        System.out.println("after");
    }
}

//public class StudentAOP implements MethodInterceptor {
//
//    @Override
//    public Object invoke(MethodInvocation invocation) throws Throwable {
//        System.out.println("haha");
//        Object ret = invocation.proceed();
//        System.out.println("wuwu");
//        return ret;
//    }
//}

//public class StudentAOP implements MethodBeforeAdvice, AfterReturningAdvice {
//    @Override
//    public void before(Method method, Object[] args, Object target) throws Throwable {
//        System.out.println("before:");
//    }
//
//    @Override
//    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
//        System.out.println("after-return");
//    }
//}




//public class StudentAOP {
//    public void afterStudy(JoinPoint point){
//        System.out.println("hahahaha"+point.getArgs()[0]+"无敌");
//    }
//    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("before");
//        String arg = joinPoint.getArgs()[0]+"666";
//        joinPoint.proceed(new Object[]{arg});
//        System.out.println("after");
//    }
//}
